import { CheckUtil } from './check';

/** URL相关包 **/
export const UrlUtil = {
  /**
   * 获取 URL 的查询参数
   * URL 请求：http://localhost:63342/test.html?operation=list|insert => "list|insert"
   * @param name
   * @returns {*}
   */
  getQueryString(name) {
    if (!CheckUtil.isBrowser()) {
      return '';
    }

    const re = new RegExp('(^|&)' + name + '=([^&]*)(&|$)'),
      params =
        window.location.search ||
        (window.location.href.indexOf('?') !== -1
          ? window.location.href.substring(window.location.href.indexOf('?'), window.location.href.length)
          : ''),
      res = params.substr(1).match(re),
      select = 2;
    return res ? unescape(res[select]) : '';
  },
};
